package com.qingluan.dd;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import com.qingluan.dd.InetTool.Bitmap_deal;;


public class MainActivity extends Activity {
	private ListView contetn;
	private Bitmap_deal bitmapTool ;
	private Button Persin_info ,Mission_info,Create_miss,Game_send;
	private My_listViewAdapter  list_adapter;
	private ListView TaskList;
	private Thread netThread;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		list_adapter = new  My_listViewAdapter();
		TaskList = (ListView)findViewById(R.id.New_Mission);
		TaskList.setAdapter(list_adapter);
		
		
		if (netThread == null){
			netThread = new Thread(runnable_net);
			netThread.start();
		}else {
			netThread.destroy();
		}
	}

	
	/*
	 * this is for list's adapter
	 * 
	 */
	class My_listViewAdapter extends BaseAdapter{
		TextView new_mission_name ,new_mission_describe;
		ImageView new_mission_p;
		
		private Context context = MainActivity.this;
		ArrayList<HashMap<String,Object>> BitmapData = new ArrayList<HashMap<String,Object>>();
		ArrayList<HashMap<String,String[]>> TextData = new ArrayList<HashMap<String,String[]>>();
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return TextData.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return TextData.get(position);
		}
		
		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}
		

		public void  addBitmapData(String mission_name,Bitmap bitmap){
			HashMap<String,Object> map = new HashMap<String,Object>();
			map.put(mission_name, bitmap);
			if(map != null){
				BitmapData.add(map);
				notifyDataSetChanged();
			}
		}
		public  void addTextData(String mission_name,String[] TextContent){
			HashMap<String,String[]> conText= new HashMap<String,String[]>();
			conText.put(mission_name, TextContent);
			if (conText != null){
				TextData.add(conText);
				this.notifyDataSetChanged();
			}
			
			
			
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.mene_list_item,null);
			new_mission_name = (TextView)convertView.findViewById(R.id.new_mission_name);
			new_mission_describe = (TextView)convertView.findViewById(R.id.new_mission_describe);
			new_mission_p = (ImageView)findViewById(R.id.new_mission_p);
			return convertView;
		}
		
	}
	
	
	/*
	 * this is for handle net thread;
	 * msg will include msg.obj :content,
	 * 					msg.what : information for content.
	 */
	Handler handle_Net = new Handler(){
		@Override
		public void handleMessage(Message msg){
			super.handleMessage(msg);
			//some content .....
			
		}
	};
	
	/*
	 * this is for get data from internet.
	 */
	Runnable runnable_net = new Runnable(){

		@Override
		public void run() {
			// TODO Auto-generated method stub
			//do something here....
			while (true){
				/*
				 * 
				 * this is for net class
				 */
			}
		}
		
	};
	
	
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	

}
